//
//  TravelNotesViewController.m
//  TravelFirst
//
//  Created by lanou on 15/9/18.
//  Copyright (c) 2015年 吴娅君. All rights reserved.
//

#import "TravelNotesViewController.h"
#import "TravelNotesTableViewController.h"
#import "TravelNotesCollectionViewController.h"

@interface TravelNotesViewController ()

@property (nonatomic, strong) TravelNotesTableViewController *travelTableVC;
@property (nonatomic, strong) TravelNotesCollectionViewController *travelCollectionVC;

@end

@implementation TravelNotesViewController

- (void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBar.alpha = 1;
    self.navigationController.tabBarController.tabBar.alpha = 1;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    
    self.navigationController.navigationBar.translucent = NO;
    
    self.travelTableVC = [[TravelNotesTableViewController alloc] init];
    self.travelTableVC.view.frame = CGRectMake(0, 0, kWidth, kHeight - 64 - 49);
    [self addChildViewController:self.travelTableVC];
    
    UICollectionViewFlowLayout *flowLayout = [[UICollectionViewFlowLayout alloc] init];
    self.travelCollectionVC = [[TravelNotesCollectionViewController alloc] initWithCollectionViewLayout:flowLayout];
    self.travelCollectionVC.view.frame = CGRectMake(0, 0, kWidth, kHeight - 49);
    [self addChildViewController:self.travelCollectionVC];
    
    [self.view addSubview:self.travelCollectionVC.view];
    
    // 直播推荐
    [self setSegmentedeControl];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

// 直播推荐
- (void)setSegmentedeControl
{
    NSMutableArray *segmentedArray = [NSMutableArray arrayWithObjects:@"直播", @"推荐", nil];
    UISegmentedControl *segmentedControl = [[UISegmentedControl alloc] initWithItems:segmentedArray];
    segmentedControl.frame = CGRectMake(0, 0, kWidth - 10, 30);
    [segmentedControl addTarget:self action:@selector(transformView:) forControlEvents:UIControlEventValueChanged];
    segmentedControl.tintColor = [UIColor blueColor];
    segmentedControl.selectedSegmentIndex = 1;
    self.navigationItem.titleView = segmentedControl;
}

- (void)transformView:(UISegmentedControl *)segmentedControl
{
    if (segmentedControl.selectedSegmentIndex == 0) {
        
        [UIView transitionFromView:self.travelCollectionVC.view toView:self.travelTableVC.view duration:0.5 options:UIViewAnimationOptionTransitionCrossDissolve completion:nil];
    } else {
        [UIView transitionFromView:self.travelTableVC.view toView:self.travelCollectionVC.view duration:0.5 options:UIViewAnimationOptionTransitionCrossDissolve completion:nil];
    }
}



@end
